package com.secneo.appshare.api.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.util.Xml;

import com.mime.qweibo.OauthKey;
import com.mime.qweibo.QAsyncHandler;
import com.mime.qweibo.QParameter;
import com.mime.qweibo.QWeiboRequest;
import com.secneo.appshare.R;
import com.secneo.appshare.api.LocalStore;
import com.secneo.appshare.api.RemoteApi;
import com.secneo.appshare.common.ActivityUtil;
import com.secneo.appshare.common.Constants;
import com.secneo.appshare.common.Util;
import com.secneo.appshare.database.AppFile;
import com.secneo.appshare.database.AppMdSha;
import com.secneo.appshare.privatemsg.PrivateMsg;
import com.secneo.appshare.remind.Remind;
import com.secneo.appshare.remind.Remind.RemindAction;

public class RemoteApiImpl implements RemoteApi {

	private static final String TAG = "RemoteApiImpl";
	
	private String getDevice() {
		return Build.MODEL;
	}
	
	private int getSdk() {
		return Build.VERSION.SDK_INT;
	}
	
	private String getAvatar() {
		return "builtin:23";
	}
	
	
	private String getLang() {
		Locale locale = Locale.getDefault();
		return locale.getLanguage();
	}
	
	private String getCountry() {
		Locale locale = Locale.getDefault();
		return locale.getCountry();
	}
	
	private String getOperator(Context c) {
		StringBuilder sb = new StringBuilder();
		String brand = String.valueOf(Build.BRAND);
		sb.append(brand);
		sb.append("/");
		TelephonyManager telephonyManager =
			((TelephonyManager) c.getSystemService(c.TELEPHONY_SERVICE));
		String operator = telephonyManager.getNetworkOperatorName();
		sb.append(operator);
		return sb.toString();
	}
	
	
	@Override
	public UserInfo addNewUser(Context c, String recomAndroidId, String nickName, String avatar,
			String password,String email,String bnumber,String uid) {
		// TODO Auto-generated method stub
		JSONObject user = new JSONObject();
		
		try {
			JSONObject info = new JSONObject();
			info.put("device", getDevice());
			info.put("sdk", getSdk());
			info.put("avatar", "buildin:" + avatar);
			info.put("lang", getLang());
			info.put("operator", getOperator(c));
			info.put("name", nickName);
			info.put("password", password);
			info.put("email", email);
			info.put("country", getCountry());
			
			int b = 0 ;
			if(bnumber.length()>0){
				b = Integer.valueOf(bnumber);
			}
			info.put("andrAccout", b);
			
			int x = 0 ;
			if(recomAndroidId.length()>0){
				x = Integer.valueOf(recomAndroidId);
			}
			info.put("recomAndrId", x) ;
			
			info.put("id", uid) ;
			//user.put("user", info);	
			info.put("appver", "apprec");
			info.put("ver", 31);
			JSONObject obj =null;
			obj = HttpComm.sendJSONToServer(Constants.NEW_USER_POST_URL, info, Constants.HTTP_SO_TIMEOUT);
			if (obj == null) {
				return null;
			} 
			UserInfo ret = new UserInfo();
			ret.nick = obj.getString("name");
			ret.id = obj.getString("id");
			ret.error = obj.getString("error");
			ret.androidId = ""+obj.getInt("andrAccount");
			return ret;
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}
	/**
	 */
		public PushMessage pushMessage(Context c) {
			// TODO Auto-generated method stub
			try {
				JSONObject info = new JSONObject();
				info.put("n",1);
				JSONObject obj = HttpComm.sendJSONToServer(Constants.PUSH_MESSAGE, info, Constants.HTTP_SO_TIMEOUT);
				JSONArray jsArray = (JSONArray)obj.get("push");
				List<Medals> ret1 = new ArrayList<Medals>();
				JSONObject obj1 = (JSONObject) jsArray.get(0);
				PushMessage ret = new PushMessage();
				ret.pushMessage = obj1.getString("message");
				ret.appName = obj1.getString("name");
				ret.appIcon = obj1.getString("appIcon");
				ret.pushTitle=obj1.getString("pushTitle");
				ret.pushYOBOUrl=obj1.getString("pushUrl");
				ret.pushFirstButton=obj1.getString("firstButtonText");
				ret.pushSecondButton=obj1.getString("secondButtonText");
				ret.pushStatus=obj1.getInt("status");
				ret.appPackageName=obj1.getString("packageName");
				
				return ret;
			} catch (Exception ex) {
				ex.printStackTrace();
				return null;
			}
		}
/**
 * user login
 * @param c
 * @param nickName
 * @param password
 * @return
 */
	public UserInfo loginUser(Context c, int  andrAccount,String password) {
		// TODO Auto-generated method stub
		JSONObject user = new JSONObject();
		
		try {
				JSONObject info = new JSONObject();
				info.put("andrAccount", andrAccount);
				info.put("password",password);
			
			JSONObject obj = HttpComm.sendJSONToServer(Constants.LOGIN_USER_POST_URL, info, Constants.HTTP_SO_TIMEOUT);
			UserInfo ret = new UserInfo();
			ret.id = obj.getString("id");
			ret.error = obj.getString("error");
			ret.avatar=obj.getString("avatar");
			ret.nick=obj.getString("name");
			return ret;
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}
	/**
	 * modify password
	 * @param c
	 * @param uId
	 * @param oldPassword
	 * @param newPassword
	 * @return
	 */
	public String modifyUserPassword(Context c, String  uId,final String oldPassword,final String newPassword) {
		// TODO Auto-generated method stub
		JSONObject user = new JSONObject();
		try {
				JSONObject info = new JSONObject();
				info.put("uid", uId);
				info.put("oldPassword", oldPassword);
				info.put("newPassword", newPassword);
			
			JSONObject obj = HttpComm.sendJSONToServer(Constants.MODIFY_USER_PASSWORD_POST_URL, info, Constants.HTTP_SO_TIMEOUT);
			if(obj == null){
				return "net_error" ;
			}
			return obj.getString("status");
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}
	
	public String lostUserPassword(Context c, String  name) {
		// TODO Auto-generated method stub
		JSONObject user = new JSONObject();
		try {
				JSONObject info = new JSONObject();
				info.put("andrAccount", name);
			JSONObject obj = HttpComm.sendJSONToServer(Constants.LOST_USER_PASSWORD_POST_URL, info, Constants.HTTP_SO_TIMEOUT);
			return obj.getString("status");
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}
	public List<Medals> getMedals(Context c, String  uId) {
		// TODO Auto-generated method stub
		JSONObject user = new JSONObject();
		try {
				JSONObject info = new JSONObject();
				info.put("uid", uId);
			JSONObject response = HttpComm.sendJSONToServer(Constants.GETMEDALS_POST_URL, info, Constants.HTTP_SO_TIMEOUT);

			if (response == null) {
				return null;
			} 
			JSONArray jsArray = (JSONArray)response.get("medals");
			List<Medals> ret = new ArrayList<Medals>();
			for(int i = 0; i < jsArray.length(); i++) {
				JSONObject obj = (JSONObject) jsArray.get(i);
				Medals app = new Medals();
				app.name = obj.getString("name");
				app.hasit = obj.getBoolean("hasIt");
				ret.add(app);
			}
			return ret;
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}
	
	@Override
	public UserInfo addNewWeiboUser(Context c, int snsType, String wid, String nickname, String avatar)
	{
		Log.d("addNewWeiboUser wid = ", wid) ;
		Log.d("addNewWeiboUser nickname = ", nickname) ;
		Log.d("addNewWeiboUser avatar = ", avatar) ;
		try 
		{
			String uid = LocalStore.getLocaleStoreInstance(c).getUid();
			JSONObject info = new JSONObject();
			info.put("device", getDevice());
			info.put("sdk", getSdk());
			info.put("avatar", avatar);
			info.put("snsType", String.valueOf(snsType));
			info.put("snsAccount", wid);
			info.put("id", uid);
			info.put("lang", getLang());
			info.put("operator", getOperator(c));
			info.put("name", nickname);
			info.put("country", getCountry());
			info.put("appver", "apprec");
			info.put("ver", 31);
			
			JSONObject obj = HttpComm.sendJSONToServer(Constants.NEW_USER_POST_URL, info, Constants.HTTP_SO_TIMEOUT);
			UserInfo ret = new UserInfo();
			
			ret.nick = obj.getString("name");
			if("".equalsIgnoreCase(ret.nick))
				ret.nick = nickname;
			ret.id = obj.getString("id");
			int androidId = obj.getInt("andrAccount");
			ret.androidId = Integer.toString(androidId);
			
			if(uid != null && !(uid.equals("")) && uid != ""){
				if(!(uid.equals(ret.id))){
					//如果uid不相同，说明此社区之前已经绑定过，需要登出本地账号才可以登录新的sns
					ret.id = Constants.SNS_HAS_ASSOCIATE ;
				}
			}
			return ret;
		} catch (Exception ex) {
			Log.d("MyTag", "error: "+ex.getMessage());
			return null;
		}
	}
	@Override
	public List<AppRecom> getRecomsApp(Context c, String uid, int appType,
			int number) {
		// TODO Auto-generated method stub
		JSONObject recoms = new JSONObject();
		JSONObject response = null; 
		try {
			if(Constants.APP_TYPE_SEARCH==appType)
			{
				recoms.put("searchName", uid);
				response = HttpComm.sendJSONToServer(Constants.SEARCH_APP_URL, recoms, Constants.HTTP_SO_TIMEOUT);

				if (response == null) {
					return null;
				} 
				JSONArray jsArray = (JSONArray)response.get("datas");
				List<AppRecom> ret = new ArrayList<AppRecom>();
				for(int i = 0; i < jsArray.length(); i++) {
					JSONObject obj = (JSONObject) jsArray.get(i);
					AppRecom app = new AppRecom();
					app.app_icon = obj.getString("appIcon");
					app.package_name = obj.getString("packageName");
					app.app_name = obj.getString("appName");
					app.price = obj.getString("price");
					app.app_icon_drawable = null;
					ret.add(app);
				}
				return ret;
			}
			else
			{
				recoms.put("n", String.valueOf(number));
				recoms.put("uid", uid);
				recoms.put("app_type", appType);
				recoms.put("ver", String.valueOf(Constants.VERSION_CODE));
				Date d = new Date();
				int timezone = d.getTimezoneOffset();
				recoms.put("timezone", String.valueOf(timezone));
				long time = d.getTime();
				recoms.put("time", String.valueOf(time));
				response = HttpComm.sendJSONToServer(Constants.RECOM_APP_POST_URL, recoms, Constants.HTTP_SO_TIMEOUT);

				if (response == null) {
					return null;
				} 
				JSONArray jsArray = (JSONArray)response.get("recoms");
				List<AppRecom> ret = new ArrayList<AppRecom>();
				for(int i = 0; i < jsArray.length(); i++) {
					JSONObject obj = (JSONObject) jsArray.get(i);
					AppRecom app = new AppRecom();
					app.app_type = obj.getInt("app_type");
					app.app_icon = obj.getString("app_icon");
					app.package_name = obj.getString("package_name");
					app.app_name = obj.getString("app_name");
					app.price = obj.getString("price");
					app.app_icon_drawable = null;
					ret.add(app);
				}
				return ret;
			}
			
		} catch(Exception ex) {
			return null;
		}
		
		
	}
	

	@Override
	public List<String> getTopPhones(Context c, int number) 
	{
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try 
		{
			feed.put("number", number);
			feedResponse = HttpComm.sendJSONToServer(Constants.FEED_GET_TOP_PHONES_URL, feed, Constants.HTTP_SO_TIMEOUT);
			
			if (feedResponse == null) 
				return null;
			JSONArray jsArray = (JSONArray)feedResponse.get("type");
			List<String> phoneList = new ArrayList<String>();
			for(int i = 0; i < jsArray.length(); i++) 
			{
				phoneList.add(jsArray.getString(i));
			}
			return phoneList;

		} catch (Exception ex) {
			Log.d("MyTag", "getTopPhones error: "+ex.getMessage());
			return null;
		}
	}
	
	

	@Override
	public Feeds getFeedsByPhone(Context c, String uid, int number, String phoneType) 
	{
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try 
		{
			feed.put("n", number);
			feed.put("uid", uid);
			feed.put("feedType", "all");
			feed.put("ver", Constants.VERSION_CODE);
			feed.put("phone", phoneType);
			feedResponse = HttpComm.sendJSONToServer(Constants.FEED_GET_POST_BYPHONE_URL, feed, Constants.HTTP_SO_TIMEOUT);
			
			if (feedResponse == null) 
				return null;
			int total = feedResponse.getInt("total");
			JSONArray jsArray = (JSONArray)feedResponse.get("feeds");
			Feeds ret = new Feeds();
			ret.total = total;
			ret.feeds = new ArrayList<Feed>();
			for(int i = 0; i < jsArray.length(); i++) 
			{
				JSONObject obj = (JSONObject) jsArray.get(i);
				Feed f = new Feed();
				f.uid = obj.getString("uid");
				f.user_name = obj.getString("userName");
				f.user_icon = obj.getString("userIcon");
				f.snsType = obj.getInt("snsType");
				if(obj.has("attent")){
					f.is_attent = obj.getInt("attent");
				}
				f.user_icon_drawable = c.getResources().getDrawable(R.drawable.some_user);
				ret.feeds.add(f);
			}
			return ret;

		} catch (Exception ex) {
			Log.d("MyTag", "getFeedsByPhone error: "+ex.getMessage());
			return null;
		}
	}
	

	@Override
	public Feeds getNotAttentFeeds(Context c, String uid, int number)
	{
		//Constants.USER_TYPE_REQUEST_ATTENT
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try 
		{
			feed.put("n", number);
			feed.put("uid", uid);
			feedResponse = HttpComm.sendJSONToServer(Constants.GET_NOT_ATTENT_URL, feed, Constants.HTTP_SO_TIMEOUT);
			
			if (feedResponse == null) 
				return null;
			JSONArray jsArray = (JSONArray)feedResponse.get("feeds");
			Feeds ret = new Feeds();
			ret.total = feedResponse.getInt("total");
			ret.feeds = new ArrayList<Feed>();
			for(int i = 0; i < jsArray.length(); i++) 
			{
				JSONObject obj = (JSONObject) jsArray.get(i);
				Feed f = new Feed();
				f.uid = obj.getString("uid");
				f.user_name = obj.getString("userName");
				f.user_icon = obj.getString("userIcon");
				f.snsType = obj.getInt("snsType");
				boolean requestSent = obj.getBoolean("status");
				if(requestSent){
					f.is_attent = 1;
				}
				else{
					f.is_attent = 0;
				}
				f.user_icon_drawable = c.getResources().getDrawable(R.drawable.some_user);
				ret.feeds.add(f);
			}
			return ret;

		} catch (Exception ex) {
			Log.d("MyTag", "getNotAttentFeeds error: "+ex.getMessage());
			return null;
		}
	}

	@Override
	public Feeds getNeedAttentFeeds(Context c, String uid, int number)
	{
		//Constants.USER_TYPE_RECEIVED_ATTENT
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try 
		{
			feed.put("n", number);
			feed.put("uid", uid);
			feedResponse = HttpComm.sendJSONToServer(Constants.GET_NEED_ATTENT_URL, feed, Constants.HTTP_SO_TIMEOUT);
			
			if (feedResponse == null) 
				return null;
			JSONArray jsArray = (JSONArray)feedResponse.get("feeds");
			Feeds ret = new Feeds();
			if(feedResponse.has("total")){
				ret.total = feedResponse.getInt("total");
			}
			ret.feeds = new ArrayList<Feed>();
			for(int i = 0; i < jsArray.length(); i++) 
			{
				JSONObject obj = (JSONObject) jsArray.get(i);
				Feed f = new Feed();
				f.uid = obj.getString("uid");
				f.user_name = obj.getString("userName");
				f.user_icon = obj.getString("userIcon");
				f.snsType = obj.getInt("snsType");
				f.is_attent = 0;
				f.user_icon_drawable = c.getResources().getDrawable(R.drawable.some_user);
				ret.feeds.add(f);
			}
			return ret;

		} catch (Exception ex) {
			Log.d("MyTag", "getNeedAttentFeeds error: "+ex.getMessage());
			return null;
		}
	}
	

	@Override
	public Feeds getFeeds(Context c, String uid, String feedType, int number) 
	{
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try 
		{
			if(feedType.equals(Constants.USER_TYPE_FIELD))
			{
				feed.put("n", number);
				feed.put("uid", uid);
				feed.put("feedType", "all");
				feed.put("ver", Constants.VERSION_CODE);
				feedResponse = HttpComm.sendJSONToServer(Constants.FEED_GET_POST_URL, feed, Constants.HTTP_SO_TIMEOUT);
			}
			else if(feedType.equals(Constants.USER_TYPE_FOLLOWER) 
					|| feedType.equals(Constants.USER_TYPE_FOLLOWED)
					|| feedType.equals(Constants.USER_TYPE_MY_ATTENT)
					|| feedType.equals(Constants.USER_TYPE_MY_FANS))
			{
				SharedPreferences sp = c.getSharedPreferences(Constants.PRE_USER_INFO, 0);
				String wid = sp.getString(Constants.USER_ID, "");
				String token = sp.getString(Constants.ACCESS_TOKEN, "");
				String tokenSecret = sp.getString(Constants.ACCESS_TOKEN_SECRET, "");
				feed.put("n", number);			
				feed.put("wid", wid);
				feed.put("snsType", "1");//todo
				feed.put("id", uid);
				String getUid = LocalStore.getLocaleStoreInstance(c).getUid();
				feed.put("currId", getUid);
				if(uid.equals(getUid))
				{
					feed.put("token", token);
					feed.put("tokenSecret", tokenSecret);
				}else
				{
					feed.put("token", "");
					feed.put("tokenSecret", "");
				}

				if(feedType.equals(Constants.USER_TYPE_FOLLOWER))
					feedResponse = HttpComm.sendJSONToServer(Constants.GET_FOLLOWER_LIST_URL, feed, Constants.HTTP_SO_TIMEOUT);
				else if(feedType.equals(Constants.USER_TYPE_MY_FANS))
					feedResponse = HttpComm.sendJSONToServer(Constants.GET_FOLLOWER_LIST_URL, feed, Constants.HTTP_SO_TIMEOUT);
				else if(feedType.equals(Constants.USER_TYPE_MY_ATTENT))
					feedResponse = HttpComm.sendJSONToServer(Constants.GET_FOLLOWED_LIST_URL, feed, Constants.HTTP_SO_TIMEOUT);
				else
					feedResponse = HttpComm.sendJSONToServer(Constants.GET_FOLLOWED_LIST_URL, feed, Constants.HTTP_SO_TIMEOUT);
			}
			else if(feedType.equals(Constants.USER_TYPE_SEARCH))
			{		
				feed.put("searchName", uid);
				feedResponse = HttpComm.sendJSONToServer(Constants.SEARCH_USER_URL, feed, Constants.HTTP_LO_TIMEOUT);
			}
			
			if (feedResponse == null) 
				return null;
			JSONArray jsArray = (JSONArray)feedResponse.get("feeds");
			Feeds ret = new Feeds();
			ret.feeds = new ArrayList<Feed>();

			if(feedResponse.has("total")){
				ret.total = feedResponse.getInt("total");
			}
			if(feedResponse.has("fansTotal")){
				ret.fansTotal = feedResponse.getInt("fansTotal");
			}
			if(feedResponse.has("attentTotal")){
				ret.attentTotal = feedResponse.getInt("attentTotal");
			}
			for(int i = 0; i < jsArray.length(); i++) 
			{
				JSONObject obj = (JSONObject) jsArray.get(i);
				Feed f = new Feed();
				f.uid = obj.getString("uid");
				f.user_name = obj.getString("userName");
				f.user_icon = obj.getString("userIcon");
				f.snsType = obj.getInt("snsType");
				f.is_new = obj.getBoolean("new");
				if(f.is_new){
					f.is_new = true;
				}
				if(obj.has("isFans")){
					f.is_fans = obj.getInt("isFans");
				}
				if(obj.has("isAttent")){
					f.is_attent = obj.getInt("isAttent");
				}
				f.user_icon_drawable = c.getResources().getDrawable(R.drawable.some_user);
				ret.feeds.add(f);
			}
			return ret;

		} catch (Exception ex) {
			Log.d("MyTag", "getFeeds error: "+ex.getMessage());
			return null;
		}
	}
	
	public AppInfo getApplicationInfo(Context c, String package_name, int number, String uid,
			boolean installed_not_addicted)
	{
		JSONObject app = new JSONObject();
		JSONObject appResponse = null;
		try {
			
			app.put("package_name", package_name);
			app.put("n", number);
			app.put("uid", uid);
			app.put("ver", Constants.VERSION_CODE);
			app.put("installed_not_addicted", installed_not_addicted);
			
			appResponse = HttpComm.sendJSONToServer(Constants.GET_APPINFO_POST_URL, 
					app, Constants.HTTP_SO_TIMEOUT);
			
			if(appResponse != null){
				AppInfo appInfo = new AppInfo() ;
				appInfo.appDetails = new AppDetails() ;
				appInfo.status = appResponse.getString("status") ;
				if(appInfo.status.equals("ok")){
					appInfo.appDetails.downloadCount = appResponse.getInt("downloadCount") ;
					appInfo.appDetails.is_active = appResponse.getBoolean("is_active") ;
					if(appResponse.getString("app_type").equals("应用"))
						appInfo.appDetails.app_type = 1 ;
					else
						appInfo.appDetails.app_type = 2 ;
					appInfo.appDetails.icon_url = appResponse.getString("icon_url") ;
					appInfo.appDetails.package_name = appResponse.getString("package_name") ;
					appInfo.appDetails.app_version = appResponse.getString("ver") ;
					appInfo.appDetails.userCount = appResponse.getInt("userCount") ;
					appInfo.appDetails.shortUrlList = new ArrayList<String>() ;
					JSONArray shortUrlArray = appResponse.getJSONArray("shotArray") ;
					for(int i = 0 ; i < shortUrlArray.length() ; ++i){
						appInfo.appDetails.shortUrlList.add(shortUrlArray.getString(i)) ;
					}
					appInfo.appDetails.hotflag = appResponse.getBoolean("hotflag") ;
					appInfo.appDetails.app_size = appResponse.getString("size") ;
					appInfo.appDetails.category = "" + appResponse.getInt("category") ;
					appInfo.appDetails.price = appResponse.getString("price") ;
					appInfo.appDetails.hotcount = "" + appResponse.getInt("hotcount") ;
					appInfo.appDetails.description = appResponse.getString("description") ;
					appInfo.appDetails.hide = appResponse.getBoolean("hidden") ;
					appInfo.appDetails.download_url = appResponse.getString("download_url") ;
					appInfo.appDetails.name = appResponse.getString("name") ;
					appInfo.appDetails.rating = appResponse.getDouble("rating") ;
					
					return appInfo ;
				} else {
					return appInfo ;
				}
			} else {
				return null ;
			}
		} catch(Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}	
	
	public CommentInfo getApplicationComments(Context c, String package_name, int number, String uid,
			boolean installed_not_addicted, int count, String timeStamp){
		JSONObject app = new JSONObject();
		JSONObject appResponse = null;
		try {
			
			app.put("package_name", package_name);
			app.put("n", number);
			app.put("uid", uid);
			app.put("ver", Constants.VERSION_CODE);
			app.put("installed_not_addicted", installed_not_addicted);
			app.put("timestamp", timeStamp) ;
			app.put("count", count) ;
			
			appResponse = HttpComm.sendJSONToServer(
					Constants.GET_APPCOMMENTS_POST_URL, 
					app, Constants.HTTP_SO_TIMEOUT);
			
			if(appResponse != null){
				CommentInfo commentInfo = new CommentInfo() ;
				commentInfo.status = appResponse.getString("status") ;
				commentInfo.commentList = new ArrayList<Comment>() ;
				if(commentInfo.status.equals("ok")){
					commentInfo.timeStamp = appResponse.getString("timestamp") ;
					JSONArray commentArray = appResponse.getJSONArray("data") ;
					
					int count1 = commentArray.length() ;
					for(int i = 0 ; i < count1 ; ++ i){
						JSONObject commentObj = commentArray.getJSONObject(i) ;
						Comment comment = new Comment() ;
						comment.uid = commentObj.getString("uid") ;
						comment.rating = commentObj.getInt("rating") ;
						comment.date = commentObj.getString("createDate") ;
						comment.user_icon = commentObj.getString("user_icon") ;
						comment.comment = commentObj.getString("comment") ;
						comment.uname = commentObj.getString("uname") ;
						commentInfo.commentList.add(comment) ;
					}
					return commentInfo ;
				} else {
					return commentInfo ;
				}
			} else {
				return null ;
			}
		} catch (Exception e) {
			return null ;
		}
	}
	public AppInfoUserInfo getApplicationUsers(Context c, String package_name, int number, String uid,
			boolean installed_not_addicted, int count, String timeStamp){
		JSONObject app = new JSONObject();
		JSONObject appResponse = null;
		try {
			
			app.put("package_name", package_name);
			app.put("n", number);
			app.put("uid", uid);
			app.put("ver", Constants.VERSION_CODE);
			app.put("installed_not_addicted", installed_not_addicted);
			app.put("timestamp", timeStamp) ;
			app.put("count", count) ;
			
			appResponse = HttpComm.sendJSONToServer(
					Constants.GET_APPUSERS_POST_URL, 
					app, Constants.HTTP_SO_TIMEOUT);
			
			if(appResponse != null){
				AppInfoUserInfo userInfo = new AppInfoUserInfo() ;
				userInfo.status = appResponse.getString("status") ;
				userInfo.timeStamp = appResponse.getString("timestamp") ;
				userInfo.userList = new ArrayList<Feed>() ;
				if(userInfo.status.equals("ok")){
					JSONArray userArray = appResponse.getJSONArray("users") ;
					int count1 = userArray.length() ;
					for(int i = 0 ; i < count1 ; ++i){
						JSONObject userObj = userArray.getJSONObject(i) ;
						Feed feed = new Feed() ;
						feed.uid = userObj.getString("uid") ;
						feed.user_name = userObj.getString("uname") ;
						feed.user_icon = userObj.getString("icon_url") ;
						feed.snsType = userObj.getInt("sns_type") ;
						userInfo.userList.add(feed) ;
					}
					return userInfo ;
				} else {
					return userInfo ;
				}
			} else {
				return null ;
			}
		} catch (Exception e) {
			e.printStackTrace() ;
			return null ;
		}
	}
	
	public OtherUserApps getOtherUserApps(Context c, String uid, String other_uid) {
		JSONObject otherUserObj = new JSONObject();
		JSONObject otherUserResponse = null;
		try {
			otherUserObj.put("uid", uid);
			otherUserObj.put("other_uid", other_uid);
			otherUserObj.put("ver", Constants.VERSION_CODE);
			
			otherUserResponse = HttpComm.sendJSONToServer(Constants.OTHER_USER_INFO_URL, 
					otherUserObj, Constants.HTTP_SO_TIMEOUT);
			
			if (otherUserResponse == null) {
				return null;
			}
			
			String status = otherUserResponse.getString("status");
			
			OtherUserApps ret = new OtherUserApps();
			
			if (!status.equals("ok")) {
				ret.status = status;
				return ret;
			}
			ret.status = status;
			ret.otherUserAppList = new ArrayList<OtherUserApp>();
			ret.numInstall = otherUserResponse.getInt("numInstall");
			ret.numShare = otherUserResponse.getInt("numShare");
			ret.numFollowed = otherUserResponse.getInt("numAttent");
			ret.numFollower = otherUserResponse.getInt("numFans");
			ret.relation = otherUserResponse.getInt("relation");
			ret.snsType = otherUserResponse.getInt("snsType");
			ret.phoneType = otherUserResponse.getString("phoneType");
			
			JSONArray medalJsArray = (JSONArray)otherUserResponse.get("medals");
			ret.medalNum = medalJsArray.length();
			ret.medals_url = new ArrayList<String>();
			List<ApplicationInfo> filteredApps =null;
			 PackageManager pm = c.getPackageManager();
			List<ApplicationInfo> allApps = pm.getInstalledApplications(0);
			filteredApps = Util.filterUserApps(allApps);
			for(int i=0; i<ret.medalNum; i++)
			{
				JSONObject obj = medalJsArray.getJSONObject(i);
				String medal_url = obj.getString("medal_icon_url");
				ret.medals_url.add(medal_url);
			}
			
			JSONObject objdata = otherUserResponse.getJSONObject("data");
			JSONArray jsArray = (JSONArray)objdata.get("apps");
			for(int i = 0; i < jsArray.length(); i++) {
				// 临时fix:只有格式完全正确的才加入列表中
				try {
				OtherUserApp app = new OtherUserApp();
				JSONObject obj = jsArray.getJSONObject(i);
				app.package_name = obj.getString("package_name");
				app.action = obj.getString("action");
				app.icon_url = obj.getString("icon_url");
				app.price = obj.getString("price");
				app.name = obj.getString("name");
				
				for(int j=0;j<filteredApps.size();j++)
				{
					ApplicationInfo ai=filteredApps.get(j);
					if(app.package_name.equals(ai.packageName))
					{
					app.selfAppFlag=true;
					break;
					}
				}
				
				ret.otherUserAppList.add(app);
				} catch (JSONException ex) {
					System.out.println("JSONException " + ex.toString());
					ex.printStackTrace();
				}
			}
			String uname = otherUserResponse.getString("uname");
			ret.uname = uname;
			//ret.snsType = otherUserResponse.getInt("snsType");
			return ret;
		} catch(Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}
	
	public String getAppFile(Context c, String uid, int type, ArrayList<AppFile> getAppFile)
	{
		JSONObject feed = new JSONObject();
		JSONArray feeds = new JSONArray();
		JSONObject feedResponse = null;
		try
		{
			JSONObject info = null;
			JSONObject appFile = null;
			feed.put("id", uid);
			feed.put("sendType", type);
			for (int i = 0; i < getAppFile.size(); i++)
			{
				info = new JSONObject();
				AppFile af = getAppFile.get(i);
				if (af.getHidden() == 1)
				{
					info.put("shared", true);
				} else
				{
					info.put("shared", false);
				}
				if (af.getIsFavorite() == 1)
				{
					info.put("favorite", true);
				} else
				{
					info.put("favorite", false);
				}

				info.put("rcDelta", 0);
				appFile = new JSONObject();
				appFile.put("name", af.getName());
				appFile.put("packageName", af.getPackageName());
				info.put("appFile", appFile);
				feeds.put(info);
			}

			feed.put("userMappAppSet", feeds);
			feed.put("ver", Constants.VERSION_CODE);
			feed.put("firstTime", true);

			feedResponse = HttpComm.sendJSONToServer(Constants.SEND_APPFILE_URL, feed, Constants.HTTP_SO_TIMEOUT);
			if (feedResponse == null)
			{
				return null;
			}
			String status = feedResponse.getString("status");
			System.out.println("statusstatus=" + status);

			return status;
		} catch (Exception ex)
		{
			ex.printStackTrace();
			return null;
		}
	}

	public String getAppMdSha(Context c, String uid,ArrayList<AppMdSha> getAppMdSha) {
		// TODO Auto-generated method stub
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try {
			JSONObject appFile =  null;
			JSONArray info = new JSONArray();
			feed.put("uid", uid);
			for(int i=0;i<getAppMdSha.size();i++)
			{
				AppMdSha appMdSha=getAppMdSha.get(i);
				
				appFile = new JSONObject();
				appFile.put("packageName", appMdSha.getPackageName());
				appFile.put("md5", appMdSha.getAppMd5());
				appFile.put("sha", appMdSha.getAppSha());
				if(!"".equals(appMdSha.getVersion())&&appMdSha.getVersion()!=null)
				{
				appFile.put("version",appMdSha.getVersion());
				}else
				{
					appFile.put("version","");
				}
				appFile.put("memo", appMdSha.getMemo());
				appFile.put("status", appMdSha.getStatus());
				info.put(appFile);
			}
			feed.put("apps", info);
			
			feedResponse = HttpComm.sendJSONToServer(Constants.SEND_MD5_URL, 
					feed, Constants.HTTP_SO_TIMEOUT);
			if (feedResponse == null) {
				return null;
			}
			String status= feedResponse.getString("status");
			System.out.println("getAppFileByUninststatus="+status);

			return status;
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
		
	}


	/**
	 * 
	 * shangchuanyonghu huodong
	 * 
	 * pinglun,yincang
	 */
	
	public JSONObject getUserAction(Context c, String id, String comments,
			String appname,String action) {
		// TODO Auto-generated method stub
		JSONObject recoms = new JSONObject();
		JSONObject response = null; 
		try {
			
			recoms.put("id", id);
			recoms.put("action", action);//2
			recoms.put("comments",comments);
			recoms.put("appname", appname);

			response = HttpComm.sendJSONToServer(Constants.SEND_ACTIONS_POST_URL, recoms, Constants.HTTP_SO_TIMEOUT);
			
			if (response == null) {
				return null;
			} 
			return response;
		} catch(Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}


	@Override
	public List<LatestActivity> getLatestActivity(Context c, String uid, int number, String time)
	{
		JSONObject lastest = new JSONObject();
		JSONObject response = null; 
		try {
			lastest.put("n", String.valueOf(number));
			lastest.put("id", uid);
			lastest.put("action", "getAllActivity");
			lastest.put("time", time);
			response = HttpComm.sendJSONToServer(Constants.GET_ALL_ACT_POST_URL, lastest, Constants.HTTP_SO_TIMEOUT);
			
			if (response == null) 
			{
				return null;
			}
			JSONArray jsArray = (JSONArray)response.get("data");
			Constants.nowTime=response.getString("time");
			List<LatestActivity> ret = new ArrayList<LatestActivity>();
			for(int i = 0; i < jsArray.length(); i++) 
			{
				JSONObject obj = (JSONObject) jsArray.get(i);
				LatestActivity app = new LatestActivity();
				app.user_name = obj.getString("username");
				app.user_icon = obj.getString("usericon");
				app.user_id = obj.getString("userid");
				app.date = ActivityUtil.transferTimeFormat(c, obj.getString("date"));
				app.action_type = obj.getInt("action");
				app.comments = obj.getString("comments");
				app.app_name = obj.getString("name");
				app.app_icon = obj.getString("icon");
				app.app_pckName = obj.getString("pckname");
				
				app.sns_type = 0;
				if(obj.has("snsType")){
					app.sns_type = obj.getInt("snsType");
				}
				
				app.user_icon_drawable = null;
				app.app_icon_drawable = null;
				
				ret.add(app);
			}
			Log.d("error", "ddd");
			return ret;
			
		} catch(Exception ex) {
			ex.printStackTrace();
			Log.d("MyTag", "error: "+ex.getMessage());
			return null;
		}
	}

	@Override
	public List<UserActivity> getUserActivity(Context c, String uid, int number)
	{
		JSONObject lastest = new JSONObject();
		JSONObject response = null; 
		try {
			lastest.put("n", String.valueOf(number));
			lastest.put("id", uid);
			lastest.put("action", "getUserActivity");
			response = HttpComm.sendJSONToServer(Constants.GET_ALL_ACT_POST_URL, lastest, Constants.HTTP_SO_TIMEOUT);
			
			if (response == null) 
			{
				return null;
			}
			JSONArray jsArray = (JSONArray)response.get("data");
			List<UserActivity> ret = new ArrayList<UserActivity>();
			for(int i = 0; i < jsArray.length(); i++) 
			{
				JSONObject obj = (JSONObject) jsArray.get(i);
				UserActivity app = new UserActivity();
				app.date = ActivityUtil.transferTimeFormat(c, obj.getString("date"));
				app.action_type = obj.getInt("action");
				app.comments = obj.getString("comments");
				app.app_name = obj.getString("name");
				app.app_icon = obj.getString("icon");
				app.app_pckName = obj.getString("pckname");
				app.app_icon_drawable = null;
				ret.add(app);
			}
			return ret;
			
		} catch(Exception ex) {
			Log.d("MyTag", "error: "+ex.getMessage());
			return null;
		}
	}

	@Override
	public void sendDownloadAction(Context c, String appName)
	{
		String uid = LocalStore.getLocaleStoreInstance(c).getUid();
		try 
		{
			JSONObject info = new JSONObject();
			info.put("id", uid);
			info.put("action", 4);
			info.put("comments", "");
			info.put("appname", appName);
			
			HttpComm.sendJSONToServer(Constants.SEND_ACTIONS_POST_URL, info, Constants.HTTP_SO_TIMEOUT);

		} catch (Exception ex) {
			Log.d("MyTag", "error: "+ex.getMessage());
		}
	}
	
	@Override
	public void sendDownLog(Context c, String appName, String shopName)
	{
		String uid = LocalStore.getLocaleStoreInstance(c).getUid();
		try 
		{
			JSONObject info = new JSONObject();
			info.put("id", uid);
			info.put("shopname", shopName);
			info.put("appname", appName);
			
			HttpComm.sendJSONToServer(Constants.SEND_DOWN_LOG_URL, info, Constants.HTTP_SO_TIMEOUT);

		} catch (Exception ex) {
			Log.d("MyTag", "error: "+ex.getMessage());
		}
	}

	@Override
	public String sendShareAction(Context c, String appName)
	{
		String uid = LocalStore.getLocaleStoreInstance(c).getUid();
		JSONObject response = null;
		String status="";
		try 
		{
			JSONObject info = new JSONObject();
			info.put("id", uid);
			info.put("action", 1);
			info.put("comments", "");
			info.put("appname", appName);
			
			response =HttpComm.sendJSONToServer(Constants.SEND_ACTIONS_POST_URL, info, Constants.HTTP_SO_TIMEOUT);
			if (response == null) 
				return status;
			
			status=response.getString("status");
		} catch (Exception ex) {
			Log.d("MyTag", "error: "+ex.getMessage());
		}
		return status;
	}

	@Override
	public void getTopList(Context c, String uid, int number, List<AppRecom> downList, List<AppRecom> hotList, 
			List<AppRecom> talkList, List<AppRecom> promoteList, List<AppRecom> goodList)
	{
		JSONObject getTopList = new JSONObject();
		JSONObject response = null; 
		try 
		{
			getTopList.put("n", number);
			getTopList.put("id", uid);
			response = HttpComm.sendJSONToServer(Constants.GET_TOP_LIST_URL, getTopList, Constants.HTTP_SO_TIMEOUT);	
			if (response == null) 
				return;
			
			JSONArray jsDownListArray = (JSONArray)response.get("downList");
			for(int i = 0; i < jsDownListArray.length(); i++) 
			{
				try
				{
					JSONObject obj = (JSONObject) jsDownListArray.get(i);
					AppRecom app = new AppRecom();
					app.app_icon = obj.getString("iconUrl");
					app.package_name = obj.getString("packageName");
					app.app_name = obj.getString("name");
					app.app_type = 0;
					app.price = "free";
					app.app_icon_drawable = null;
					downList.add(app);
				
				} catch(Exception ex) {
					Log.d("MyTag", "getTopList 1 error: "+ex.getMessage());
				}
			}
			
			JSONArray jsHotListArray = (JSONArray)response.get("topList");
			for(int i = 0; i < jsHotListArray.length(); i++) 
			{
				try
				{
					JSONObject obj = (JSONObject) jsHotListArray.get(i);
					AppRecom app = new AppRecom();
					app.app_icon = obj.getString("iconUrl");
					app.package_name = obj.getString("packageName");
					app.app_name = obj.getString("name");
					app.app_type = 0;
					app.price = "free";
					app.app_icon_drawable = null;
					hotList.add(app);
				
				} catch(Exception ex) {
					Log.d("MyTag", "getTopList 2 error: "+ex.getMessage());
				}
			}
			
			JSONArray jsTalkListArray = (JSONArray)response.get("commentList");
			for(int i = 0; i < jsTalkListArray.length(); i++) 
			{
				try
				{
					JSONObject obj = (JSONObject) jsTalkListArray.get(i);
					AppRecom app = new AppRecom();
					app.app_icon = obj.getString("iconUrl");
					app.package_name = obj.getString("packageName");
					app.app_name = obj.getString("name");
					app.app_type = 0;
					app.price = "free";
					app.app_icon_drawable = null;
					talkList.add(app);
				
				} catch(Exception ex) {
					Log.d("MyTag", "getTopList 3 error: "+ex.getMessage());
				}
			}

			JSONArray jsPromoteListArray = (JSONArray)response.get("promoteList");
			for(int i = 0; i < jsPromoteListArray.length(); i++) 
			{
				try
				{
					JSONObject obj = (JSONObject) jsPromoteListArray.get(i);
					AppRecom app = new AppRecom();
					app.app_icon = obj.getString("iconUrl");
					app.package_name = obj.getString("packageName");
					app.app_name = obj.getString("name");
					app.app_type = 0;
					app.price = "free";
					app.app_icon_drawable = null;
					promoteList.add(app);
				
				} catch(Exception ex) {
					Log.d("MyTag", "getTopList 4 error: "+ex.getMessage());
				}
			}
			
			JSONArray jsGoodListArray = (JSONArray)response.get("promoteList");
			for(int i = 0; i < jsGoodListArray.length(); i++) 
			{
				try
				{
					JSONObject obj = (JSONObject) jsGoodListArray.get(i);
					AppRecom app = new AppRecom();
					app.app_icon = obj.getString("iconUrl");
					app.package_name = obj.getString("packageName");
					app.app_name = obj.getString("name");
					app.app_type = 0;
					app.price = "free";
					app.app_icon_drawable = null;
					goodList.add(app);
				
				} catch(Exception ex) {
					Log.d("MyTag", "getTopList 4 error: "+ex.getMessage());
				}
			}
			
		} catch(Exception ex) {
			Log.d("MyTag", "getTopList error: "+ex.getMessage());
			return;
		}
	}

	@Override
	public boolean followSomeone(Context c, String otherUid, boolean isFollow)
	{
		String uid = LocalStore.getLocaleStoreInstance(c).getUid();
		JSONObject info = new JSONObject();
		JSONObject response = null; 
		try 
		{
			info.put("uid", uid);
			info.put("otherUid", otherUid);
			info.put("isFollow", isFollow);
			response = HttpComm.sendJSONToServer(Constants.FOLLOW_SOMEONE_URL, info, Constants.HTTP_SO_TIMEOUT);
			if (response == null) 
				return false;
			String status = response.getString("status");
			if(status.equals("ok"))
				return true;
			else
				return false;

		} catch (Exception ex) {
			Log.d("MyTag", "followSomeone error: "+ex.getMessage());
		}
		return false;
	}
	

	
	public boolean extractKeyword(StringBuffer retWord, StringBuffer wholeString)
	{
		int start = wholeString.indexOf("\"", 0);
		if(start==-1){
			return false;
		}
		int end = wholeString.indexOf("\"", start+1);
		if(end==-1){
			return false;
		}
		
		retWord.setLength(0);
		retWord.append(wholeString.substring(start+1, end));
		wholeString.delete(0, end+1);
		return true;
	}
	

	@Override
	public int getHotKeyword(Context c, int count, List<String> wordList)
	{
		JSONObject info = new JSONObject();
		JSONObject response = null; 
		try 
		{
			info.put("total", count);
			response = HttpComm.sendJSONToServer(Constants.GET_KEYWORD_URL, info, Constants.HTTP_SO_TIMEOUT);
			if (response == null) 
				return 0;
			
			JSONArray jskeywordArray = (JSONArray)response.get("hotword");
			if(jskeywordArray.length()>0){
			//	JSONObject obj = (JSONObject) jskeywordArray.get(0);
				StringBuffer wordStr = new StringBuffer(jskeywordArray.toString());
				StringBuffer singleWord = new StringBuffer();
				while(extractKeyword(singleWord, wordStr)){
					wordList.add(singleWord.toString());
				}
			}
		} catch (Exception ex) {
			Log.d("MyTag", "followSomeone error: "+ex.getMessage());
		}
		return wordList.size();
	}
	

	@Override
	public String getEmail(Context c, String userId)
	{
		JSONObject info = new JSONObject();
		JSONObject response = null; 
		JSONArray jskeywordArray = null;
		String emailString="";
		try 
		{
			info.put("id", userId);
			response = HttpComm.sendJSONToServer(Constants.GET_EMAIL_URL, info, Constants.HTTP_SO_TIMEOUT);
			if (response == null) {
				return "";
			}
			
			emailString = response.getString("email");
			
		} catch (Exception ex) {
			Log.d("MyTag", "followSomeone error: "+ex.getMessage());
		}
		return emailString;
	}
	

	@Override
	public boolean sendSnsInfo(Context c, String userId, 
			String snsUserName, String snsIconUrl, int snsType)
	{
		JSONObject info = new JSONObject();
		JSONObject response = null; 
		JSONArray jskeywordArray = null;
		try 
		{
			info.put("id", userId);
			info.put("snsUser", snsUserName);
			info.put("snsIcon", snsIconUrl);
			info.put("snsType", String.valueOf(snsType));
			response = HttpComm.sendJSONToServer(Constants.SEND_SNSINFO_URL, info, Constants.HTTP_SO_TIMEOUT);
			if (response == null) {
				return false;
			}
			
			String status = response.getString("status");
			if(status.equals("ok"))
				return true;
			else
				return false;
			
		} catch (Exception ex) {
			Log.d("MyTag", "followSomeone error: "+ex.getMessage());
		}
		return true;
	}
	

	@Override
	public boolean destroySNSAccount(Context c, String userId, int snsType)
	{
		JSONObject info = new JSONObject();
		JSONObject response = null; 
		JSONArray jskeywordArray = null;
		try 
		{
			info.put("userId", userId);
			info.put("snsType", String.valueOf(snsType));
			response = HttpComm.sendJSONToServer(Constants.DESTROY_SNSACCOUNT_URL, info, Constants.HTTP_SO_TIMEOUT);
			if (response == null) {
				return false;
			}
			
			String status = response.getString("status");
			if(status.equals("ok"))
				return true;
			else
				return false;
			
		} catch (Exception ex) {
			Log.d("MyTag", "followSomeone error: "+ex.getMessage());
		}
		return true;
	}

	@Override
	public boolean destroyBangAccount(Context c, String userId)
	{
		JSONObject info = new JSONObject();
		JSONObject response = null; 
		JSONArray jskeywordArray = null;
		try 
		{
			info.put("userId", userId);
			response = HttpComm.sendJSONToServer(Constants.DESTROY_BANGACCOUNT_URL, info, Constants.HTTP_SO_TIMEOUT);
			if (response == null) {
				return false;
			}
			
			String status = response.getString("status");
			if(status.equals("ok"))
				return true;
			else
				return false;
			
		} catch (Exception ex) {
			Log.d("MyTag", "followSomeone error: "+ex.getMessage());
		}
		return true;
	}
	
	@Override
	public int sendMsg(String f_uid, String t_uid, String data) {
		
		Log.d("TAG" , "sendMsg f_uid = " + f_uid + "t_uid" + t_uid) ;
		
		JSONObject obj = new JSONObject() ;
		
		try {
			obj.put("otherUid", t_uid) ;
			obj.put("uid", f_uid) ;
			obj.put("sms", data) ;
		} catch (JSONException e) {
			e.printStackTrace();
			return -1 ;
		}
		
		JSONObject ret_obj = HttpComm.sendJSONToServer(Constants.SEND_MSG_URL, obj, Constants.HTTP_SO_TIMEOUT);
		
		if(ret_obj == null){
			return -1 ;
		}
		
		try {
			String ret_str = (String)ret_obj.get("status") ;
			if("ok".equals(ret_str))	
				return 1 ;
			else if("error".equals(ret_str))
				return -1 ;
		} catch (JSONException e) {
			e.printStackTrace();
			return -1 ;
		}
		
		return -1;
	}
	
	@Override
	public ArrayList<PrivateMsg> recieveMsg(Context c , String uid , int pageIndex){
		
		JSONObject obj = new JSONObject() ;
		
		ArrayList<PrivateMsg> list = null ;
		
		try{
			obj.put("id", uid) ;
			obj.put("action", "getMessages") ;
			obj.put("n", pageIndex) ;
		} catch (JSONException e){
			e.printStackTrace();
			return list ;
		}
		
		JSONObject ret_obj = HttpComm.sendJSONToServer(
				Constants.RECEIVE_MSG_URL, obj, 
				Constants.HTTP_SO_TIMEOUT);
		
		if(ret_obj == null){
			return list ;
		}
		
		try {
			list = new ArrayList<PrivateMsg>() ;
			JSONArray array = ret_obj.getJSONArray("data") ;
			int count = array.length() ;
			for(int i = 0 ; i < count ; ++i){
				JSONObject f_obj = (JSONObject)array.get(i) ;
				PrivateMsg msg = new PrivateMsg() ;
				msg.setO_username(f_obj.getString("userName")) ;
				msg.setFid(f_obj.getString("userId")) ;
				msg.setTid(uid) ;
				msg.setO_iconurl(f_obj.getString("userIcon")) ;
				msg.setMsg_id(f_obj.getInt("msg_id")) ;
				try{
					msg.setTime(ActivityUtil.transferTimeFormat(c , 
							f_obj.getString("date"))) ;
				} catch(ParseException ex){
					msg.setTime("don't know") ;
					ex.printStackTrace() ;
				}
				msg.setNew(f_obj.getBoolean("isNew")) ;
				msg.setData(f_obj.getString("message")) ;
				list.add(msg) ;
				
			}
			
		} catch (JSONException e) {
			e.printStackTrace();
			return list ;
		}
		
		return list ;
	}
	
	public ArrayList<PrivateMsg> recieveMsgByUid(Context c , 
			String uid , String o_uid , int pageIndex){
		JSONObject obj = new JSONObject() ;
		
		ArrayList<PrivateMsg> list = null ;
		
		try {
			//{"uid":"sdfe134dsf1234", “other_uid”:”1234564324455”}
			obj.put("uid", uid) ;
			obj.put("otherUid", o_uid) ;
			obj.put("n", pageIndex) ;
		} catch (JSONException e) {
			e.printStackTrace();
			return list ;
		}
		
		JSONObject ret_obj = HttpComm.sendJSONToServer(
				Constants.RECEIVE_MSG_URL_BY_UID, obj, 
				Constants.HTTP_SO_TIMEOUT);
		
		//如果返回结果为空
		if(ret_obj == null){
			return list ;
		}
		
		try {
			list = new ArrayList<PrivateMsg>() ;
			JSONArray array = ret_obj.getJSONArray("dialogs") ;
			int count = array.length() ;
			for(int i = 0 ; i < count ; ++i){
				JSONObject f_obj = (JSONObject)array.get(i) ;
				PrivateMsg msg = new PrivateMsg() ;
				msg.setO_username(f_obj.getString("name")) ;
				msg.setFid(o_uid) ;
				msg.setTid(uid) ;
				msg.setO_iconurl(f_obj.getString("icon")) ;
				try{
					msg.setTime(ActivityUtil.transferTimeFormat(c , 
							f_obj.getString("date"))) ;
				} catch(ParseException ex){
					msg.setTime("don't know") ;
					ex.printStackTrace() ;
				}
				msg.setNew(f_obj.getBoolean("isNew")) ;
				msg.setMsg_id(f_obj.getInt("msg_id")) ;
				msg.setData(f_obj.getString("msg")) ;
				list.add(msg) ;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return list ;
		}
		
		return list ;
	}
	
	public int getNews(String uid , News news){
		Log.d("TAG" , "getNews uid = " + uid) ;
		JSONObject obj = new JSONObject() ;
		
		try{
			obj.put("uid", uid) ;
		} catch (JSONException e){
			e.printStackTrace();
			return -1 ;
		}
		
		JSONObject ret_obj = HttpComm.sendJSONToServer(
				Constants.GET_NEWS_URL, obj, 
				Constants.HTTP_SO_TIMEOUT);
		
		if(ret_obj == null){
			return -1 ;
		}
		
		boolean sameNotify = false;
		try{
			news.newSmsCount = ret_obj.getInt("newSms") ;
			news.newActivityCount = ret_obj.getInt("newActivity") ;
			news.newFanCount = ret_obj.getInt("newFan") ;			
			news.newHonorCount = ret_obj.getInt("newMedal") ;
			Log.d("TAG" , "getNews newSmsCount = " + news.newSmsCount) ;
			Log.d("TAG" , "getNews newActivityCount = " + news.newActivityCount) ;
			Log.d("TAG" , "getNews newFanCount = " + news.newFanCount) ;
			Log.d("TAG" , "getNews newHonor = " + news.newHonorCount) ;
			if( !ret_obj.isNull("smsMd5") ){
				String smsMd5String = ret_obj.getString("smsMd5") ;
				String localSmsMd5String=LocalStore.getLocaleStoreInstance().getRemindSmsMd5();
				String fanMd5String = ret_obj.getString("fanMd5") ;
				String localFanMd5String=LocalStore.getLocaleStoreInstance().getRemindFanMd5();
				String honorMd5String = ret_obj.getString("medalMd5") ;
				String localHonorMd5String=LocalStore.getLocaleStoreInstance().getRemindHonorMd5();
				boolean sameSms = smsMd5String.equals(localSmsMd5String);
				Log.d("TAG" , "Same Sms Md5: " + sameSms) ;
				if(!sameSms){
					LocalStore.getLocaleStoreInstance().setRemindSmsMd5(smsMd5String);
				}
				boolean sameFan = fanMd5String.equals(localFanMd5String);
				Log.d("TAG" , "Same Fan Md5: " + sameFan) ;
				if(!sameFan){
					LocalStore.getLocaleStoreInstance().setRemindFanMd5(fanMd5String);
				}
				boolean sameHonor = honorMd5String.equals(localHonorMd5String);
				Log.d("TAG" , "Same honor Md5: " + sameHonor) ;
				if(!sameHonor){
					LocalStore.getLocaleStoreInstance().setRemindHonorMd5(honorMd5String);
				}
				sameNotify = sameSms || sameFan || sameHonor;
			}
		} catch (JSONException e){
			e.printStackTrace();
			return -1 ;
		}
		
		if(sameNotify){
			return -1;
		}
		else{
			return 1 ;
		}
	}
	
	public int deleteMsg(String uid , int msg_uid){
		
		JSONObject obj = new JSONObject() ;
		
		try{
			obj.put("uid", uid) ;
			obj.put("msg_id", msg_uid) ;
		} catch (JSONException e){
			e.printStackTrace();
			return -1 ;
		}
		
		JSONObject ret_obj = HttpComm.sendJSONToServer(
				Constants.DELETE_MSG_URL, obj, 
				Constants.HTTP_SO_TIMEOUT);
		
		if(ret_obj == null){
			return -1 ;
		}
		
		try {
			String ret_str = (String)ret_obj.get("status") ;
			if("ok".equals(ret_str))	
				return 1 ;
			else if("error".equals(ret_str))
				return -1 ;
			else
				return -1 ;
		} catch (JSONException e) {
			e.printStackTrace();
			return -1 ;
		}
	}
	
	public ArrayList<Remind> getRemindList(Context c , String uid, int actionType){
		
		ArrayList<Remind> list = null ;
		
		JSONObject obj = new JSONObject() ;
		
		try{
			obj.put("uid", uid) ;
			obj.put("action", "getNotes") ;
		} catch (JSONException e){
			e.printStackTrace();
			return list ;
		}

		JSONObject ret_obj=null;
		ret_obj = HttpComm.sendJSONToServer(
				Constants.GET_REMIND_LIST_URL, obj, 
				Constants.HTTP_SO_TIMEOUT);
		
		if(ret_obj == null){
			return list ;
		}
		
		try{
			list = new ArrayList<Remind>() ;
			JSONArray array = ret_obj.getJSONArray("data") ;
			int count = array.length() ;
			for(int i = 0 ; i < count ; ++i){
				JSONObject item = (JSONObject)array.get(i) ;
				Remind remind = new Remind() ;
				remind.setUserName(item.getString("username")) ;
				remind.setUserIconUrl(item.getString("usericon")) ;
				remind.setUserId(item.getString("userid")) ;
				try{
					remind.setDate(ActivityUtil.transferTimeFormat(c , 
							item.getString("date"))) ;
				} catch(ParseException ex){
					remind.setDate("don't know") ;
					ex.printStackTrace() ;
				}
				remind.setAction(item.getInt("action")) ;
				if(remind.getAction() == RemindAction.NEWCOMMENTACTION){
					remind.setComments(item.getString("comments")) ;
				}
				if(remind.getAction() == RemindAction.NEWSHAREACTION ||
						remind.getAction() == RemindAction.NEWCOLLECTIONACTION ||
						remind.getAction() == RemindAction.NEWCOMMENTACTION ||
						remind.getAction() == RemindAction.NEWDOWNLOADACTION){
					remind.setAppName(item.getString("name")) ;
					remind.setAppIconUrl(item.getString("icon")) ;
					remind.setPakageName(item.getString("pckName")) ;
				}
				remind.setData() ;
				list.add(remind) ;
				Log.d("TAG" , 
						"remind :  " + i + "action = " + remind.getAction() + "  " + remind.getAppName()) ;
			}
		} catch (Exception e) {
			e.printStackTrace() ;
			return list ;
		}
		
		return list ;
	}
	
	public boolean share2QWeiboMsg(Context ctx, int actionType, String msg, 
			byte[] imageBytes, String atWho , String appDes , String pkgName){

		if(Constants.SWITCH_SINA_CUSTOM){
			return true;
		}
		
		String str = null;

		String downloadLink = null ;
		String finishingWord = null;
		if(pkgName != null)
		{
			downloadLink = ctx.getString(R.string.download_link , pkgName) ;
		}
		else
		{
			downloadLink = ctx.getString(R.string.download_link_no_pkgname) ;
		}

		finishingWord = ctx.getString(R.string.finishing_word) ;
		
		if (actionType == Constants.UPLOAD_ACTION_SHARE_WEIBO)
		{
			if (atWho == null)
				str = ctx.getString(R.string.action_share_weibo, msg);
			else
				//str = ctx.getString(R.string.action_share_weibo_at, msg, atWho);
				str = ctx.getString(R.string.action_share_weibo_at, msg);

			str = str + "(" + downloadLink + " )" + " " + appDes + finishingWord;
		} 
		else if (actionType == Constants.UPLOAD_ACTION_DOWN)
		{
			str = ctx.getString(R.string.action_down, msg);
			str = str + "(" + downloadLink + " )" + " " + appDes + finishingWord;
		}
		else if (actionType == Constants.UPLOAD_ACTION_LOGIN)
		{
			str = ctx.getString(R.string.suggest_app);
		}
		else if (actionType == Constants.UPLOAD_ACTION_LIKE)
		{
			str = ctx.getString(R.string.action_like, msg);
			str = str + "(" + downloadLink + " )" + " " + appDes + finishingWord;
		}
		else if (actionType == Constants.UPLOAD_ACTION_TALK)
		{
			str = ctx.getString(R.string.action_talk, msg);
			str = str + "  (" + downloadLink + " )" + " " + finishingWord;
		}
		
		
		Log.d("MyTag", "--------qweibo str = " + str);
		
		List<QParameter> params = new ArrayList<QParameter>(1);
		params.add(new QParameter("content", str)) ;
		params.add(new QParameter("Clientip", "127.0.0.1")) ;
		List<QParameter> files = new ArrayList<QParameter>(1);
		OauthKey authKey = new OauthKey();
		authKey.customKey = Constants.QWEIBO_APP_KEY ;
		authKey.customSecrect = Constants.QWEIBO_APP_SECRET;
		authKey.tokenKey = LocalStore.getLocaleStoreInstance(ctx).qWeiboAccessToken() ;
		authKey.tokenSecrect = LocalStore.getLocaleStoreInstance(ctx).
									qWeiboAccessTokenSecret() ;
		
		File file = new File("/data/data/"+Constants.PACKAGENAME+"/tmp.png");
		if( file.exists()) {
			file.delete() ;
	    } 
		
    	try {
			file.createNewFile();
			FileOutputStream stream = new FileOutputStream(file);
			stream.write(imageBytes) ;
			files.add(new QParameter("pic", "/data/data/"+Constants.PACKAGENAME+"/tmp.png")) ;
			QWeiboRequest request = new QWeiboRequest();
			boolean ret = request.asyncRequest(
					"http://open.t.qq.com/api/t/add_pic", 
					"POST", authKey, params,
					files, new QAsyncHandler() {
						String mContent = "";
						
						@Override
						public void onThrowable(Throwable t,
								Object cookie) {
							mContent = "Request throw exception:"
									+ t.getLocalizedMessage();
						}

						@Override
						public void onCompleted(int statusCode,
								String content, Object cookie) {
							mContent = content;
						}
					}, null);
			return ret ;
		} catch (IOException e) {
			e.printStackTrace();
			return false ;
		} catch (Exception e) {
			e.printStackTrace() ;
			return false ;
		}
	}
	
	
	public boolean share2QWeiboMsg(Context ctx, int actionType, String msg, 
			String atWho, String appDes , String pkgName){

		if(Constants.SWITCH_SINA_CUSTOM){
			return true;
		}
		
		String str = null;

		String downloadLink = null ;
		String finishingWord = null;
		if(pkgName != null)
		{
			downloadLink = ctx.getString(R.string.download_link , pkgName) ;
		}
		else
		{
			downloadLink = ctx.getString(R.string.download_link_no_pkgname) ;
		}

		finishingWord = ctx.getString(R.string.finishing_word) ;
		
		if (actionType == Constants.UPLOAD_ACTION_SHARE_WEIBO)
		{
			if (atWho == null)
				str = ctx.getString(R.string.action_share_weibo, msg);
			else
				//str = ctx.getString(R.string.action_share_weibo_at, msg, atWho);
				str = ctx.getString(R.string.action_share_weibo_at, msg);

			str = str + "(" + downloadLink + ")" + " " + appDes + finishingWord;
		} 
		else if (actionType == Constants.UPLOAD_ACTION_DOWN)
		{
			str = ctx.getString(R.string.action_down, msg);
			str = str + "(" + downloadLink + ")" + " " + appDes + finishingWord;
		}
		else if (actionType == Constants.UPLOAD_ACTION_LOGIN)
		{
			str = ctx.getString(R.string.suggest_app);
		}
		else if (actionType == Constants.UPLOAD_ACTION_LIKE)
		{
			str = ctx.getString(R.string.action_like, msg);
			str = str + "(" + downloadLink + ")" + " " + appDes + finishingWord;
		}
		else if (actionType == Constants.UPLOAD_ACTION_TALK)
		{
			str = ctx.getString(R.string.action_talk, msg);
			str = str + "  (" + downloadLink + ")" + " " + finishingWord;
		}

		Log.d("MyTag", "--------qweibo str = " + str);
		
		List<QParameter> params = new ArrayList<QParameter>(1);
		params.add(new QParameter("content", str)) ;
		params.add(new QParameter("Clientip", "127.0.0.1")) ;
		List<QParameter> files = new ArrayList<QParameter>(1);
		OauthKey authKey = new OauthKey();
		authKey.customKey = Constants.QWEIBO_APP_KEY ;
		authKey.customSecrect = Constants.QWEIBO_APP_SECRET;
		authKey.tokenKey = LocalStore.getLocaleStoreInstance(ctx).qWeiboAccessToken() ;
		authKey.tokenSecrect = LocalStore.getLocaleStoreInstance(ctx).
									qWeiboAccessTokenSecret() ;
		
		
    	try {
			QWeiboRequest request = new QWeiboRequest();
			boolean ret = request.asyncRequest(
					"http://open.t.qq.com/api/t/add", 
					"POST", authKey, params,
					files, new QAsyncHandler() {
						String mContent = "";

						@Override
						public void onThrowable(Throwable t,
								Object cookie) {
							mContent = "Request throw exception:"
									+ t.getLocalizedMessage();
						}

						@Override
						public void onCompleted(int statusCode,
								String content, Object cookie) {
							mContent = content;
						}
					}, null);
			return ret ;
		} catch (Exception e) {
			e.printStackTrace();
			return false ;
		}
	}
	
	@Override
	public List<AppRecom> getFriendsList(Context c, String uid, int snsType)
	{
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try 
		{
			String wid = "";
			String token = "";
			String tokenSecret = "";
			SharedPreferences sp = c.getSharedPreferences(Constants.PRE_USER_INFO, 0);
			wid = sp.getString(Constants.USER_ID, "");
			if(snsType == 1)
			{
				token = sp.getString(Constants.ACCESS_TOKEN, "");
				tokenSecret = sp.getString(Constants.ACCESS_TOKEN_SECRET, "");
			}
			else if(snsType == 2) // 腾讯
			{
				wid = LocalStore.getLocaleStoreInstance(c).qWeiboName() ;
				token = LocalStore.getLocaleStoreInstance(c).qWeiboAccessToken() ;
				tokenSecret = LocalStore.getLocaleStoreInstance(c).qWeiboAccessTokenSecret() ;
				Log.d("qq" , "getFriends token = " + token) ;
				Log.d("qq" , "getFriends tokenSecret = " + tokenSecret) ;
			}
			else if(snsType == 3) // 开心
			{
				token = LocalStore.getLocaleStoreInstance(c).getKaixinAccessToken();
				tokenSecret = LocalStore.getLocaleStoreInstance(c).getKaixinAccessTokenSecret();
			}
			else if(snsType == 4) // 人人
			{
				token = LocalStore.getLocaleStoreInstance(c).getRenrenSessionKey() ;
				tokenSecret = LocalStore.getLocaleStoreInstance(c).getRenrenSessionSecret() ;
				if(token == null)
					token = "";
				if(tokenSecret == null)
					tokenSecret = "";
			}
			
			feed.put("wid", wid);
			feed.put("snsType", snsType);
			feed.put("id", uid);
			feed.put("token", token);
			feed.put("tokenSecret", tokenSecret);
			feedResponse = HttpComm.sendJSONToServer(Constants.GET_FRIENDS_URL, feed, 50*1000);

			/*
			final String uid = LocalStore.getLocaleStoreInstance(SearchActivity.this).getUid();
			RemoteApiImpl remoteApi = new RemoteApiImpl();
			List<AppRecom> mTalkList = new ArrayList<AppRecom>();
			mTalkList = remoteApi.getFriendsList(SearchActivity.this, uid, 4);
			*/
			
			if (feedResponse == null) 
				return null;
			
			List<AppRecom> ret = new ArrayList<AppRecom>();
			JSONArray jsFrisListArray = (JSONArray)feedResponse.get("feeds");
			for(int i = 0; i < jsFrisListArray.length(); i++) 
			{
				try
				{
					JSONObject obj = (JSONObject) jsFrisListArray.get(i);
					AppRecom app = new AppRecom();
					app.app_icon = obj.getString("userIcon");
					app.package_name = obj.getString("uid");
					app.app_name = obj.getString("userName");
					app.app_type = 1;
					ret.add(app);
				
				}catch(Exception ex) {
					Log.d("MyTag", "getFriendsList error1: "+ex.getMessage());
				}
			}
			return ret;
			
		}catch(Exception ex) {
			Log.d("MyTag", "getFriendsList error2: "+ex.getMessage());
		}
		return null;
	}

	@Override
	public boolean uploadFollowedFriends(Context c, String uid, List<String> uidList)
	{
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try 
		{
			JSONArray jsFrisListArray = new JSONArray();;
			for(int i = 0; i < uidList.size(); i++)
			{
				JSONObject obj = new JSONObject();
				obj.put("uid", uidList.get(i));
				jsFrisListArray.put(obj);
			}
			
			feed.put("id", uid);
			feed.put("feeds", jsFrisListArray);
			feedResponse = HttpComm.sendJSONToServer(Constants.UPLOAD_FRIENDS_URL, feed, Constants.HTTP_SO_TIMEOUT);
			
			if (feedResponse == null) 
				return false;
			
			if(feedResponse.getString("status").equals("error"))
				return false;
			else
				return true;
			
		}catch(Exception ex) {
			Log.d("MyTag", "getFriendsList error: "+ex.getMessage());
		}
		return false;
	}
	

	@Override
	public boolean uploadRequestAttent(Context c, String uid, List<String> uidList)
	{
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try 
		{
			JSONArray jsFrisListArray = new JSONArray();;
			for(int i = 0; i < uidList.size(); i++)
			{
				JSONObject obj = new JSONObject();
				obj.put("uid", uidList.get(i));
				jsFrisListArray.put(obj);
			}
			
			feed.put("id", uid);
			feed.put("feeds", jsFrisListArray);
			feedResponse = HttpComm.sendJSONToServer(Constants.UPLOAD_REQUEST_ATTENT_URL, feed, Constants.HTTP_SO_TIMEOUT);
			
			if (feedResponse == null) 
				return false;
			
			if(feedResponse.getString("status").equals("error"))
				return false;
			else
				return true;
			
		}catch(Exception ex) {
			Log.d("MyTag", "uploadRequestAttent error: "+ex.getMessage());
		}
		return false;
	}
	

	@Override
	public boolean uploadRejectAttent(Context c, String uid, List<String> uidList)
	{
		JSONObject feed = new JSONObject();
		JSONObject feedResponse = null;
		try 
		{
			JSONArray jsFrisListArray = new JSONArray();;
			for(int i = 0; i < uidList.size(); i++)
			{
				JSONObject obj = new JSONObject();
				obj.put("uid", uidList.get(i));
				jsFrisListArray.put(obj);
			}
			
			feed.put("id", uid);
			feed.put("feeds", jsFrisListArray);
			feedResponse = HttpComm.sendJSONToServer(Constants.UPLOAD_REJECT_ATTENT_URL, feed, Constants.HTTP_SO_TIMEOUT);
			
			if (feedResponse == null) 
				return false;
			
			if(feedResponse.getString("status").equals("error"))
				return false;
			else
				return true;
			
		}catch(Exception ex) {
			Log.d("MyTag", "uploadRejectAttent error: "+ex.getMessage());
		}
		return false;
	}
	
	
	
	@Override
	public BNumberItem getBNumber(){
		JSONObject obj = new JSONObject() ;
		JSONObject ret_obj = 
			HttpComm.sendJSONToServer(Constants.GET_USER_BNUMBER, obj, Constants.HTTP_SO_TIMEOUT) ;
		if(ret_obj == null) {
			return null ;
		}
		try {
			int ret = ret_obj.getInt("andrAccout") ;
			String id = ret_obj.getString("id") ;
			BNumberItem item = new BNumberItem() ;
			item.bnumber = "" + ret ; 
			item.uid = id ;
			return item ;
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null ;
	}
	

	@Override
	public String getSinaRegisterNumber(Context c){
		
		TelephonyManager telephonyManager =
			((TelephonyManager) c.getSystemService(c.TELEPHONY_SERVICE));
		int simState = telephonyManager.getSimState();
		String operatorKeyword = "";
		if(TelephonyManager.SIM_STATE_READY!=simState){
			operatorKeyword = "fallback";
		}
		else{

			String operator = telephonyManager.getSimOperator();
			if(null!=operator){
				Log.e("MyTag", "Sim operator: "+operator);
				if( operator.equals("46000") || operator.equals("46002") || operator.equals("46007") ){
					//中国移动
					operatorKeyword = "cmcc";
					Log.e("MyTag", "Sim: cmcc");
				}
				else if( operator.equals("46001") ){
					//中国联通
					operatorKeyword = "unicom";
					Log.e("MyTag", "Sim: unicom");
				}
				else if( operator.equals("46003") ){
					//中国电信
					operatorKeyword = "telecom";
					Log.e("MyTag", "Sim: telecom");
				}
				else{
					//其他
					operatorKeyword = "fallback";
					Log.e("MyTag", "Sim: other");
				}
			}
			else{
				operatorKeyword = "fallback";
			}
		}
		
		
		String xmlRetString = "";
		String registerNumber = "";
		try {
			
			xmlRetString = HttpComm.httpGet(Constants.SINA_REGISTER_URL, 
					"wm="+Constants.SINA_REGISTER_VM);
			
	        XmlPullParser parser = Xml.newPullParser();
            parser.setInput(new StringReader(xmlRetString));
            int evtCode = parser.getEventType();
            while (evtCode != XmlPullParser.END_DOCUMENT) {
            	switch (evtCode) {
            		case XmlPullParser.START_TAG:
                        if (operatorKeyword.equals(parser.getName())) {
                        	registerNumber = parser.nextText();
                        }
                    break;
                    }
            	if(!"".equals(registerNumber)){
            		break;
            	}
            	evtCode = parser.next();
            	}
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return registerNumber;
	}
	

	
}


